/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ThreadBasedSimulator;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FileInputStream;
import java.util.StringTokenizer;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.Timer;

/**
 *
 * @author mahesh
 */
public class SimulatorGUI extends javax.swing.JFrame {

    /**
     * Creates new form SimulatorGUI
     */
    public SimulatorGUI() {
        initComponents();
        
        // initialize all the main components of the simulator
        mainClock = new Clock();        
        threadMemory = new MemoryThread( mainClock );
        threadIO = new IOThread( mainClock );
        threadProcessor = new ProcessorThread( mainClock, threadMemory, threadIO );
        
        fc = new JFileChooser();
        
    
        ActionListener aListener = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                UpdateUIElements();
            }
        };
        
        
        timer = new Timer( 100, aListener );
        timer.start();
        
        // Initially, hide the debug console
        HideDebugConsole();
        
        
        
    }

    void HideDebugConsole()
    {
        //jPanel2.setVisible(false);
        jPanel4.setVisible(false);
        // reduce the window size
        this.setBounds(0, 0, 1027, 600);
        
    }
    void ShowDebugConsole()
    {
        //jPanel2.setVisible(true);
        jPanel4.setVisible(true);
        
        this.setBounds( 0, 0, 1275, 600);
    }    
    void UpdateUIElements()
    {
        // Check to see if the processor thread is running
        if( threadProcessor.getState() == Thread.State.RUNNABLE ||
                threadProcessor.getState() == Thread.State.WAITING )
        {
            // This means the thread is running
            //System.err.println("Processor thread running");
            // Now we can ask for the values for the different variables
            int [] nR   = threadProcessor.GetRegisters();
            int nPC     = threadProcessor.GetProgramCounter();
            int nIR     = threadProcessor.GetInstructionRegister();
            int nX0     = threadProcessor.GetIndexRegister();
            int nCC     = threadProcessor.GetConditionCode();
            int nMFR    = threadProcessor.GetMachineFaultRegister();
            int nMSR    = threadProcessor.GetMachineStatusRegister();
            int nMAR    = threadMemory.GetMAR();
            int nMDR    = threadMemory.GetMDR();
            
            int nProcessorState = threadProcessor.GetProcessorState();
            String sScreenData  = threadIO.GetScreenData();
            
            // now set the variables to their GUI elements
            
            // starting with the processor             
            lblR1.setText( "" + Integer.toBinaryString( 0x10000 | nR[0]).substring(1) );
            lblR2.setText( "" + Integer.toBinaryString( 0x10000 | nR[1]).substring(1) );
            lblR3.setText( "" + Integer.toBinaryString( 0x10000 | nR[2]).substring(1) );
            lblR4.setText( "" + Integer.toBinaryString( 0x10000 | nR[3]).substring(1) );
            
            lblX0.setText( "" + Integer.toBinaryString( 0x10000 | nX0 ).substring(1) );
            
            String temp = "";
            if( nProcessorState == ProcessorThread.PS_BOOTING_UP )
                temp = " Booting up ";
            else if( nProcessorState == ProcessorThread.PS_INSTRUCTION_FETCH )
                temp = " Fetch";
            else if( nProcessorState == ProcessorThread.PS_INSTRUCTION_DECODE )
                temp = " Decode ";
            else if( nProcessorState == ProcessorThread.PS_INSTRUCTION_EXECUTE )
                temp = " Execute ";
            
            lblProcessorState.setText("Processor State : " + temp );
            
            // next, set the program state variables, PC, IR etc. 
            lblPC.setText( "" + Integer.toBinaryString(0x10000 | nPC).substring(1) );
            lblIR.setText( "" + Integer.toBinaryString(0x10000 | nIR).substring(1) );
            lblCC.setText( "" + Integer.toBinaryString(0x10000 | nCC).substring(1) );
            lblMFR.setText( "" + Integer.toBinaryString(0x10000 | nMFR).substring(1) );
            lblMSR.setText( "" + Integer.toBinaryString(0x10000 | nMSR).substring(1) );
            
            lblMAR.setText( "" + Integer.toBinaryString(0x10000 | nMAR).substring(1) );
            lblMDR.setText( "" + Integer.toBinaryString(0x10000 | nMDR).substring(1) );
            
            // next, set the memory elements
            // last but not the least, the screen data            
            txtScreen.setText(txtScreen.getText() + sScreenData);
            
            // update the position of the cursor in the code window
            int selIndex = nIndexStartOfCode + ( nPC - 64 )/2;            
            lstCode.setSelectedIndex( selIndex );
            
            
        }
        else
        {
            // toggle the switch back to "ON"
            jToggleButton1.setSelected(true);            
        }
            
        
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        txtScreen = new javax.swing.JTextArea();
        txtKeyboard = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        lblR1 = new javax.swing.JLabel();
        lblR2 = new javax.swing.JLabel();
        lblR3 = new javax.swing.JLabel();
        lblR4 = new javax.swing.JLabel();
        lbl1 = new javax.swing.JLabel();
        lblPC = new javax.swing.JLabel();
        lbl2 = new javax.swing.JLabel();
        lblIR = new javax.swing.JLabel();
        lblCC = new javax.swing.JLabel();
        lbl3 = new javax.swing.JLabel();
        lbl4 = new javax.swing.JLabel();
        lblX0 = new javax.swing.JLabel();
        lblMSR = new javax.swing.JLabel();
        lbl5 = new javax.swing.JLabel();
        lbl6 = new javax.swing.JLabel();
        lblMFR = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblMAR = new javax.swing.JLabel();
        lblMDR = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jToggleButton1 = new javax.swing.JToggleButton();
        jButton1 = new javax.swing.JButton();
        lblProcessorState = new javax.swing.JLabel();
        cbDebugMode = new javax.swing.JCheckBox();
        cmdStep = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        lstCode = new javax.swing.JList();
        jButton2 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        lbl7 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        lbl8 = new javax.swing.JLabel();
        lblIR1 = new javax.swing.JLabel();
        lblCC1 = new javax.swing.JLabel();
        lblPC1 = new javax.swing.JLabel();
        lbl9 = new javax.swing.JLabel();
        lbl10 = new javax.swing.JLabel();
        lblR5 = new javax.swing.JLabel();
        lblR6 = new javax.swing.JLabel();
        lblR7 = new javax.swing.JLabel();
        lblR8 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(1299, 521));
        setResizable(false);

        txtScreen.setEditable(false);
        txtScreen.setColumns(20);
        txtScreen.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        txtScreen.setRows(5);
        jScrollPane1.setViewportView(txtScreen);

        txtKeyboard.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        txtKeyboard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtKeyboardActionPerformed(evt);
            }
        });
        txtKeyboard.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtKeyboardKeyTyped(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblR1.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblR1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblR2.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblR2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblR3.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblR3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblR4.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblR4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lbl1.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lbl1.setText("PC");
        lbl1.setBorder(null);

        lblPC.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblPC.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lbl2.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lbl2.setText("IR");
        lbl2.setBorder(null);

        lblIR.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblIR.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblCC.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblCC.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lbl3.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lbl3.setText("CC");
        lbl3.setBorder(null);

        lbl4.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lbl4.setText("X0");
        lbl4.setBorder(null);

        lblX0.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblX0.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblMSR.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblMSR.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lbl5.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lbl5.setText("MSR");
        lbl5.setBorder(null);

        lbl6.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lbl6.setText("MFR");
        lbl6.setBorder(null);

        lblMFR.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblMFR.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel6.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        jLabel6.setText("R1");
        jLabel6.setBorder(null);

        jLabel7.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        jLabel7.setText("R2");
        jLabel7.setBorder(null);

        jLabel8.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        jLabel8.setText("R3");
        jLabel8.setBorder(null);

        jLabel9.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        jLabel9.setText("R4");
        jLabel9.setBorder(null);

        jLabel4.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        jLabel4.setText("MAR");

        lblMAR.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblMAR.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblMDR.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblMDR.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel5.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        jLabel5.setText("MDR");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbl6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbl5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbl3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbl1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbl2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbl4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(lblR1, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(lblR2, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(lblR3, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(lblR4, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lblPC, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblIR, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblCC, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblX0, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblMSR, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblMFR, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblMAR, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addContainerGap()))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(lblMDR, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel4, jLabel5, jLabel6, jLabel7, jLabel8, jLabel9, lbl1, lbl2, lbl3, lbl4, lbl5, lbl6});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(lblR1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(lblR2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(lblR3, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(lblR4, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbl1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPC, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbl2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblIR, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbl3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblCC, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbl4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblX0, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbl5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblMSR, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbl6, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
                    .addComponent(lblMFR, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lblMAR, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblMDR, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jToggleButton1.setText("On");
        jToggleButton1.setEnabled(false);
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton1ActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        jButton1.setText("Load program");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        lblProcessorState.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblProcessorState.setText("Processor State : ");
        lblProcessorState.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblProcessorState.setFocusable(false);

        cbDebugMode.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        cbDebugMode.setText("Debug Mode");
        cbDebugMode.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        cbDebugMode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbDebugModeActionPerformed(evt);
            }
        });

        cmdStep.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        cmdStep.setText("Step");
        cmdStep.setEnabled(false);
        cmdStep.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdStepActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel3.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        jLabel3.setText("Code");

        jScrollPane2.setViewportView(lstCode);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2)
                .addContainerGap())
        );

        jButton2.setText("Debug Console");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel10.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        jLabel10.setText("Opcode");
        jLabel10.setBorder(null);

        jLabel11.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        jLabel11.setText("R1");
        jLabel11.setBorder(null);

        jLabel12.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        jLabel12.setText("R2");
        jLabel12.setBorder(null);

        lbl7.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lbl7.setText("Index");
        lbl7.setBorder(null);

        jLabel13.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        jLabel13.setText("Offset");
        jLabel13.setBorder(null);

        lbl8.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lbl8.setText("Processor");
        lbl8.setBorder(null);

        lblIR1.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblIR1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblCC1.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblCC1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblPC1.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblPC1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lbl9.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lbl9.setText("Indirect");
        lbl9.setBorder(null);

        lbl10.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lbl10.setText("Immed");
        lbl10.setBorder(null);

        lblR5.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblR5.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblR6.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblR6.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblR7.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblR7.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblR8.setFont(new java.awt.Font("Courier New", 0, 15)); // NOI18N
        lblR8.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbl7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbl10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbl9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbl8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(lblCC1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                    .addComponent(lblIR1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblPC1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblR7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblR8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblR5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblR6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbl8, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(lblR6, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(lblR5, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(lblR8, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13)
                    .addComponent(lblR7, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbl10, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPC1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbl9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblIR1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbl7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblCC1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(lblProcessorState, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cbDebugMode, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtKeyboard)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(cmdStep, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jToggleButton1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblProcessorState, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButton1)
                                .addComponent(jToggleButton1))
                            .addComponent(cbDebugMode))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(cmdStep)
                                    .addComponent(jButton2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addComponent(jScrollPane1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtKeyboard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
        // TODO add your handling code here:
        // start them all off
        threadProcessor.SetBootupFile(sBootupFile);
        
        
        if( cbDebugMode.isSelected() )
        {
            threadProcessor.SetExecutionMode( cbDebugMode.isSelected() );
            cmdStep.setEnabled(true);
        }
            
        
        mainClock.start();
        threadProcessor.start();
        threadMemory.start();
        threadIO.start();
        
        jToggleButton1.setText("OFF");
        
    }//GEN-LAST:event_jToggleButton1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        fc.showOpenDialog(this);
        File fileBinary = fc.getSelectedFile();
        
        sBootupFile = fileBinary.getAbsolutePath();
        
        jToggleButton1.setEnabled(true);
        
        // Load the code in the code window
        // We assume that the binary file has the extension .bnry and the code file has the extension .asm
        String sBinaryFilename = fileBinary.getAbsolutePath();
        String sAsmFilename = sBinaryFilename.replace(".bnry", ".asm");
        System.err.println( sAsmFilename );        
        
        // Now we have the path of the code file. Load it up in the list box
        try
        {
            File fileAsm = new File( sAsmFilename );
            FileInputStream fin = new FileInputStream( fileAsm );
            
            byte [] data = new byte[ (int)fileAsm.length() ];
            fin.read(data);
            
            String sAsmCode = new String( data );            
            StringTokenizer st = new StringTokenizer( sAsmCode, "\n" );
            System.err.println( " Num of lines in code file = " + st.countTokens() );
            
            DefaultListModel tokenList = new DefaultListModel();
            lstCode.setModel(tokenList);
            
            int index = 0;
            while( st.hasMoreTokens() )
            {
                String tempStr = st.nextToken();
                tempStr = tempStr.replace(" ", "   ");
                
                tokenList.addElement( tempStr );
                if( tempStr.equalsIgnoreCase(".code"))
                    nIndexStartOfCode = index;
                
                index++;
            }
            
            System.err.println(" code starts at " + nIndexStartOfCode);
        }
        catch( Exception ex )
        {
            System.err.println(" .asm file not found in the same directory as the binary file.");
        }
                
        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void cbDebugModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDebugModeActionPerformed
        
    }//GEN-LAST:event_cbDebugModeActionPerformed

    private void cmdStepActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdStepActionPerformed
        
        threadProcessor.StepForward();
    }//GEN-LAST:event_cmdStepActionPerformed

    private void txtKeyboardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtKeyboardActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtKeyboardActionPerformed

    private void txtKeyboardKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtKeyboardKeyTyped
        
        if( evt.getKeyChar() == KeyEvent.VK_ENTER )
        {
            // when the user presses enter, push all the data in the text field to the
            // IO buffer in the IO thread. Necessary to avoid recall while entering integers.
            threadIO.StoreToIOBuffer(txtKeyboard.getText());
            // also clear the text box
            txtKeyboard.setText("");
        }
    }//GEN-LAST:event_txtKeyboardKeyTyped

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        //jLabel1.setVisible( !jLabel1.isVisible() );
               
        if( jPanel4.isVisible() )
        {
            // hide the panels
            HideDebugConsole();
        }
        else
        {
            ShowDebugConsole();
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SimulatorGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SimulatorGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SimulatorGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SimulatorGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SimulatorGUI().setVisible(true);
            }
        });
        
        
    }
    Clock           mainClock;
    ProcessorThread threadProcessor;
    MemoryThread    threadMemory;
    IOThread        threadIO;

    JFileChooser    fc;
    String          sBootupFile;

    Timer           timer;
    int             nIndexStartOfCode;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox cbDebugMode;
    private javax.swing.JButton cmdStep;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JLabel lbl1;
    private javax.swing.JLabel lbl10;
    private javax.swing.JLabel lbl2;
    private javax.swing.JLabel lbl3;
    private javax.swing.JLabel lbl4;
    private javax.swing.JLabel lbl5;
    private javax.swing.JLabel lbl6;
    private javax.swing.JLabel lbl7;
    private javax.swing.JLabel lbl8;
    private javax.swing.JLabel lbl9;
    private javax.swing.JLabel lblCC;
    private javax.swing.JLabel lblCC1;
    private javax.swing.JLabel lblIR;
    private javax.swing.JLabel lblIR1;
    private javax.swing.JLabel lblMAR;
    private javax.swing.JLabel lblMDR;
    private javax.swing.JLabel lblMFR;
    private javax.swing.JLabel lblMSR;
    private javax.swing.JLabel lblPC;
    private javax.swing.JLabel lblPC1;
    private javax.swing.JLabel lblProcessorState;
    private javax.swing.JLabel lblR1;
    private javax.swing.JLabel lblR2;
    private javax.swing.JLabel lblR3;
    private javax.swing.JLabel lblR4;
    private javax.swing.JLabel lblR5;
    private javax.swing.JLabel lblR6;
    private javax.swing.JLabel lblR7;
    private javax.swing.JLabel lblR8;
    private javax.swing.JLabel lblX0;
    private javax.swing.JList lstCode;
    private javax.swing.JTextField txtKeyboard;
    private javax.swing.JTextArea txtScreen;
    // End of variables declaration//GEN-END:variables
}
